-- SetupWireless.applescript
-- SetupWireless

-- SetupWiFi.sh

-- SetupWireless is released under the General Public License, (C) 2008 Jeff Dyck

-- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
-- as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

-- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

-- You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

global App_Location

on launched theObject
	set App_Location to the resource path of the main bundle
end launched


on clicked theObject
	if the name of theObject is "Setup" then
		--Set some pointers to possibly changed locations on the drive...
		set App_Location to the resource path of the main bundle
		set WiFiScript to the quoted form of (App_Location & "/SetupWiFi.sh")
		
		--Grab user name and password from GUI
		set USER to the contents of text field "UserName" of window of theObject
		set PASS to the contents of secure text field "Password" of window of theObject
		
		------------------------------------------------------------------------------------
		--CHANGE THE NAME TO YOUR 802.1X WIRELESS NETWORK HERE!!!
		------------------------------------------------------------------------------------
		
		set WIRELESS to "csf-secure"
		
		------------------------------------------------------------------------------------
		
		--Run the shell script...
		set command to WiFiScript & " -u " & USER & " -p " & PASS & " -w " & WIRELESS
		do shell script command
		display window "Info" attached to window of theObject
		
	else if the name of theObject is "Finish" then
		--Turn airport off then back on to make sure it connects with these settings.ke
		stop airport
		pause 3
		start airport
		
		--Close the info window
		close panel (window "Info")
		display alert "Your wireless network is now setup and should be ready to use." attached to window "main"
	end if
	
end clicked


on should quit after last window closed theObject
	true
end should quit after last window closed

on panel ended theObject with result withResult
end panel ended

on choose menu item theObject
	if the name of theObject is "Reset" then
		set WiFiResetScript to the quoted form of (App_Location & "/resetWireless.sh")
		do shell script WiFiResetScript with administrator privileges
		display alert "Your wireless network settings have been reset."
	end if
end choose menu item
